home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / syscall / Fs_Write.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-21  |  2.6 KB  |  80 lines

  1. /* 
  2.  * Fs_Write.c --
  3.  *
  4.  *    Source code for the Fs_Write library procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: Fs_Write.c,v 1.2 88/06/21 11:14:55 ouster Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20. #include <sprite.h>
  21. #include <status.h>
  22. #include <fs.h>
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * Fs_Write --
  29.  *
  30.  *      The "normal" Fs_Write interface for user code.  Writes writeLength
  31.  *      characters from buffer to the file identified by streamID.
  32.  *      *amtWrittenPtr is updated to reflect how much data were actually
  33.  *      written.
  34.  *
  35.  *      For some kinds of devices, Fs_Write causes the calling process to
  36.  *      block until the device is ready to accept the data.  If a signal
  37.  *      is received by the process while it is blocked, then the
  38.  *      Fs_RawWrite system call will be aborted in order to process the
  39.  *      signal.  When (if) the signal returns, the system call will return
  40.  *      a GEN_ABORTED_BY_SIGNAL status, and *writeCountPtr will reflect
  41.  *      the number of bytes accepted by the device before the signal
  42.  *      occurred.  This routine will detect this occurrence and
  43.  *      automatically restart the system call to write the remainder of
  44.  *      the data.
  45.  *
  46.  * Results:
  47.  *    An error code.
  48.  *
  49.  * Side effects:
  50.  *    The file offset is incremented to be after the data written.
  51.  *    The amtWrittenPtr is updated to reflect the amount actually written.
  52.  *
  53.  *----------------------------------------------------------------------
  54.  */
  55.  
  56. ReturnStatus
  57. Fs_Write(streamID, writeLength, buffer, amtWrittenPtr)
  58.     int        streamID;    /* The user's index into its open file list */
  59.     int        writeLength;    /* The amount of bytes to write */
  60.     Address    buffer;        /* The data to be written */
  61.     int        *amtWrittenPtr;    /* The amount of bytes actually written */
  62. {
  63.     int amtWritten;
  64.     ReturnStatus status;
  65.  
  66.     *amtWrittenPtr = 0;
  67.     do {
  68.     status = Fs_RawWrite(streamID, writeLength, buffer, &amtWritten);
  69.     *amtWrittenPtr += amtWritten;
  70.     if (status == GEN_ABORTED_BY_SIGNAL) {
  71.         writeLength -= amtWritten;
  72.         if (writeLength <= 0) {
  73.         return(SUCCESS);
  74.         }
  75.         buffer += amtWritten;
  76.     }
  77.     } while (status == GEN_ABORTED_BY_SIGNAL);
  78.     return(status);
  79. }
  80.